package org.fisco.bcos.asset.controller;



import java.math.BigInteger;
import java.util.List;

import org.fisco.bcos.asset.client.CharityDonationClient;
import org.fisco.bcos.asset.resp.Application;
import org.fisco.bcos.asset.resp.BuildProject;
import org.fisco.bcos.asset.service.CharityOrgService;
import org.fisco.bcos.sdk.model.TransactionReceipt;
import org.fisco.bcos.sdk.transaction.model.exception.ContractException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/charity-org")
public class CharityOrgController {

    @Autowired
    private CharityOrgService charityOrgService;

    @Resource
    private CharityDonationClient client;

    // 创建捐赠项目
    @PostMapping("/project")
    public BuildProject createDonationProject(
            @RequestParam String projectName,
            @RequestParam String description,
            @RequestParam String beneficiaryAddress,
            @RequestParam BigInteger targetAmount) {
        return charityOrgService.createDonationProject(projectName, description, beneficiaryAddress, targetAmount);
    }

    @PostMapping("/registerRegulator")
    public void setRegulator(@RequestParam String regulatorAddress) {
        charityOrgService.setRegulator(regulatorAddress);
    }

    @PostMapping("/registerBeneficiary")
    public void setBeneficiary(@RequestParam String beneficiaryAddress) {
        charityOrgService.setBeneficiary(beneficiaryAddress);
    }

    @PostMapping("/application/{applicationId}/approve")
    public void approveApplication(@PathVariable BigInteger applicationId) {
        charityOrgService.approveApplication(applicationId);
    }

    @PostMapping("/deploy")
    public String deployCharityDonationAndRecordAddr() {
        return client.deployCharityDonationAndRecordAddr();
    }

    @GetMapping("/getAllApplications")
    public List<Application> getAllApplications() throws ContractException {
        return client.getAllApplications();
    }

}